package cn.itcast.blog.FastJson;

import java.util.Date;

import org.junit.Test;

import com.alibaba.fastjson.JSON;

import cn.itcast.blog.domain.Post;

public class testFastJson {
	
	/**
	 * 对象转成Json字符,序列化
	 */
	@Test
	public void testSerialize() {
		Post post = new Post();
		post.setId(1);
		post.setTitle("java");
		post.setContent("java");
		post.setCreated(new Date());
		
		String jsonString = JSON.toJSONString(post);
		
		System.out.println(jsonString);
	}
	
	/**
	 * json转换成java对象，反序列化
	 */
	@Test
	public void testDeSerialize() {
		String json = "{\"content\":\"java\",\"created\":1534579485036,\"id\":1,\"title\":\"java\"}";
		
		Post parseObject = JSON.parseObject(json, Post.class);
		
		System.out.println(parseObject);
	}
}
